<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>17_缓动动画（从快到慢）</title>
    <style>
        *{
            padding:0;
            margin:0;
        }
        div{
            width: 100px;
            height: 100px;
            background-color: orange;
            position: relative;
            top:0;
            left: 0;
        }
        button {
            margin-top:20px;
        }
    </style>
    <script>
        window.onload = function () {
            var div = document.getElementsByTagName("div")[0];
            var button = document.getElementsByTagName("button")[0];

            var startNum = 0;
            var endNum = document.body.clientWidth-100;
            var timer = null;
            button.onclick = function () {
                clearInterval(timer);
                timer = setInterval(function () {
                    startNum = startNum + (endNum - startNum)/10;
                    div.style.left = startNum + "px";
                },15);
            }
        }
    </script>
</head>
<body>
    <div></div>
<button>开始动画</button>
</body>
</html>